package com.ldc.service;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ldc.model.Config;
import com.ldc.service.mapper.ConfigMapper;
import com.ldc.service.service.ConfigService;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 功能说明
 *
 * @auther liudc
 * @since 2023/6/24
 */
@Service
public class ConfigServiceImpl extends ServiceImpl<ConfigMapper, Config> implements ConfigService {

    @Override
    public List<Config> findListByType(String type) {
        return findListBy(new LambdaQueryWrapper<Config>().eq(Config::getType, type));
    }

    @Override
    public List<Config> findListBy(LambdaQueryWrapper<Config> queryWrapper) {
        return getBaseMapper().selectList(queryWrapper);
    }

    @Override
    public int batchDeleteBy(LambdaQueryWrapper<Config> queryWrapper) {
        return getBaseMapper().delete(queryWrapper);
    }

    @Override
    public int batchDeleteByTypeAndKeyCode(String type, String keyName) {
        return batchDeleteBy(new QueryWrapper<Config>().lambda().eq(Config::getType, type).and(queryWrapper -> queryWrapper.eq(Config::getKeyName, keyName)));
    }
}
